<?php

namespace Database\Seeders;

use Illuminate\Database\Console\Seeds\WithoutModelEvents;
use Illuminate\Database\Seeder;
use App\Models\Message;
use App\Models\User;

class MessageTableSeeder extends Seeder
{
    public function run(): void
    {
       // 先创建 10 个用户
        $users = User::factory()->count(10)->create();

        // 为每个用户创建 5 条留言，确保 user_id 有效
        $users->each(function ($user) {
            Message::factory()
                ->count(5)
                ->for($user) // 自动关联当前用户
                ->create();
        });
    }
}
